﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ClientRegister
{
    public partial class ListStudentForm : Form
    {
        public string IDEmp { set; get; }
        public string NameEmp { set; get; }

        public ListStudentForm()
        {
            InitializeComponent();
        }

        private void EditInfoPersonForm_Load(object sender, EventArgs e)
        {
            CourseDataProvider course = new CourseDataProvider();
            DataSet dscourse = course.loadCourses();
            cbbCourse.DataSource = dscourse.Tables[0];
            cbbCourse.DisplayMember = "NameCourse";
            cbbCourse.ValueMember = "ID";
        }

        private void buttonCanCel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cbbCourse_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbCourse.SelectedValue.ToString() == "System.Data.DataRowView") return;
            else
            {
                ClassDataProvider cls = new ClassDataProvider();
                DataSet dsclass = cls.loadClass(cbbCourse.SelectedValue.ToString());
                cbbClass.DataSource = dsclass.Tables[0];
                cbbClass.DisplayMember = "NameClass";
                cbbClass.ValueMember = "ID";
            }
            StudentDataProvider listStu = new StudentDataProvider();
            DataSet ds = listStu.loadStudentInCourse(cbbCourse.SelectedValue.ToString());
            DataTable dt = ds.Tables[0];
            GridListStudent.DataSource = dt;
        }

        private void cbbClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbClass.SelectedValue.ToString() == "System.Data.DataRowView") return;
            else
            {
                StudentDataProvider listStu = new StudentDataProvider();
                DataSet ds = listStu.loadStudentInClass(cbbClass.SelectedValue.ToString(), cbbCourse.SelectedValue.ToString());
                DataTable dt = ds.Tables[0];
                GridListStudent.DataSource = dt;
            }
        }

        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            if (this.GridListStudent.SelectedCells.Count > 0)
            {

        // Goi form InfoPerson hien thong tin ca nhan cua hoc vien
                ChangeInfoPersonForm per = new ChangeInfoPersonForm();
                per.IDEmp = IDEmp;
                per.NameEmp = NameEmp;
                per.ID = GridListStudent.CurrentRow.Cells["ID"].Value.ToString();
                per.FullName = GridListStudent.CurrentRow.Cells["FullName"].Value.ToString();
                per.GenderId = GridListStudent.CurrentRow.Cells["GenderId"].Value.ToString();
                per.Birthday = GridListStudent.CurrentRow.Cells["Birthday"].Value.ToString();
                per.Career = GridListStudent.CurrentRow.Cells["Career"].Value.ToString();
                per.Email = GridListStudent.CurrentRow.Cells["Email"].Value.ToString();
                per.Phone = GridListStudent.CurrentRow.Cells["Phone"].Value.ToString();
                per.Address = GridListStudent.CurrentRow.Cells["Address"].Value.ToString();
                per.Note = GridListStudent.CurrentRow.Cells["Note"].Value.ToString();
                per.CreateDateTime = GridListStudent.CurrentRow.Cells["CreateDateTime"].Value.ToString();
                per.Show();
            }
        }
    }
}
